﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.model;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.客户CRM.Service;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.销售记录.service;
using DXApplicationTangche.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.门店下单
{
    /// <summary>
    /// 门店下单充血模型
    /// </summary>
    public class OrderModel
    {
        private List<OrderDto> orderDtos = new List<OrderDto>();
        private Boolean hasOrder = false;
        #region 属性
        public List<OrderDto> OrderDtos { get => orderDtos; set => orderDtos = value; }
        public List<OrderCommitDTO返回> orderCommitDTO返回s { get; set; } = new List<OrderCommitDTO返回>();
        public bool HasOrder { get => hasOrder; set => hasOrder = value; }
        #endregion
        /// <summary>
        /// 扫描成衣码下单的下单选款返回的orderCommitDTO添加到orderModel中,不带备注图
        /// </summary>
        /// <param name="orderCommitDTO"></param>
        /// <returns></returns>
        public OrderModel buildAddSaleSampleOrderCommitDto(OrderCommitDTO返回 orderCommitDTO)
        {
            this.orderCommitDTO返回s.Add(orderCommitDTO);
            return this;
        }
        /// <summary>
        /// 扫描成衣码下单的下单选款返回的orderCommitDTO添加到orderModel中,带备注图
        /// </summary>
        /// <param name="orderCommitDTO"></param>
        /// <returns></returns>
        public OrderModel buildAddOrderCommitDto(OrderCommitDTO返回 orderCommitDTO, List<备注DTOs> 备注DTOs)
        {
            this.orderCommitDTO返回s.Add(orderCommitDTO);
            this.OrderDtos.Add(new OrderDto(orderCommitDTO.id, 备注DTOs));
            return this;
        }
        /// <summary>
        /// 门店下单选款式新选择的订单添加到orderDTOs中
        /// </summary>
        /// <param name="dto定制下单"></param>
        /// <returns></returns>
        public OrderModel buildAddOrderDtos(Dto定制下单 dto定制下单) {
            this.orderDtos.Add(new OrderDto(dto定制下单));
            return this;
        }
        public OrderModel buildKashiyamaAddOrderDtos(Dto定制下单 dto定制下单, List<尺寸呈现dto> 尺寸呈现dtos)
        {
            this.orderDtos.Add(new OrderDto(dto定制下单).buildKashiyamaMeasureItemDTOS(尺寸呈现dtos).buildOrderSalesType(Enum订单类型.坚山订单));
            return this;
        }
        /// <summary>
        /// 增加辅料信息注入
        /// </summary>
        /// <param name="dto定制下单"></param>
        /// <param name="dto辅料"></param>
        /// <returns></returns>
        public OrderModel buildAddOrderDtos(Dto定制下单 dto定制下单, StyleAccessoryItemsDTO dto辅料, Enum订单类型 @enum)
        {
            OrderDto orderDto = new OrderDto(dto定制下单).build辅料信息(dto辅料).build订单类型(@enum);
            this.orderDtos.Add(orderDto);
            this.orderCommitDTO返回s.Add(new OrderCommitDTO返回(orderDto));
            return this;
        }

        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public OrderModel buildDeletaOrderDtos(String id) {
            foreach (OrderDto orderDto in this.OrderDtos) {
                if (id.Equals(orderDto.id)) {
                    this.OrderDtos.Remove(orderDto);
                    return this;
                }
            }
            return this;
        }

        public OrderModel buildCustomer()
        {
            foreach(OrderDto orderDto in this.OrderDtos)
            {
                orderDto.customerId = Frm客户.cUSTOMER_ID.ToString();
                orderDto.customerCountId = Frm客户.customer_countid.ToString();
                orderDto.customerName = Frm客户.customer_name;
                orderDto.addressId = Frm客户.aDDRESS_ID.ToString();
            }
            return this;
        }

        public OrderModel buildCustomer(客户CRM.Service.CustomerOrderCommitDTO address)
        {
            foreach (OrderDto orderDto in this.OrderDtos)
            {
                orderDto.customerId = Frm客户.cUSTOMER_ID.ToString();
                orderDto.customerCountId = Frm客户.customer_countid.ToString();
                orderDto.customerName = Frm客户.customer_name;
                //orderDto.addressId = Frm客户.aDDRESS_ID.ToString();
                //  
                orderDto.consignee = address.customerName;
                orderDto.mobile = address.mobile;
                orderDto.addressId = address.addressId;
                orderDto.addressProvince = address.addressProvince;
                orderDto.addressCity = address.addressCity;
                orderDto.addressDistrict = address.addressDistrict;
                orderDto.addressDetail = address.addressDetail;
                orderDto.zipCode = address.zipCode;
            }
            return this;
        }

        ///// <summary>
        ///// 坚山下单用
        ///// </summary>
        ///// <param name="i"></param>
        //public void SaveOrderInDatabase(int i)
        //{
        //    this.buildCustomer();
        //    foreach (OrderDto orderDto in OrderDtos)
        //    {
        //        OrderService.DynamicSaveOrder(orderDto, Enum订单类型.坚山订单);
        //    }
        //}
        public void CreateExcel并回执邮件()
        {

        }
    }
}
